package pl.omega.selenium;

import java.util.List;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;

import org.testng.*;
import org.testng.annotations.*;

import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;

import pl.omega.selenium.model.Film;

public class SearchBad extends pl.omega.selenium.pages.TestBase {
 /* private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();

  @Test
  public void testUntitled() throws Exception {
	WebDriverWait wait = new WebDriverWait(driver, 30);
    driver.get(baseUrl + "/php4dvd/#!/sort/name%20asc/");
    
    WebElement search = driver.findElement(By.id("q"));
    search.clear();
    search.sendKeys("bla bla" + Keys.RETURN);
    
    wait.until(ExpectedConditions.presenceOfElementLocated(By.className("content")));
    List<WebElement> filmlist2 = driver.findElements(By.className("movie_box"));
    assertEquals(0, filmlist2.size());
  }

  private boolean isElementPresent(By by) {
    try {
      driver.findElement(by);
      return true;
    } catch (NoSuchElementException e) {
      return false;
    }
  }

  private String closeAlertAndGetItsText() {
    try {
      Alert alert = driver.switchTo().alert();
      String alertText = alert.getText();
      if (acceptNextAlert) {
        alert.accept();
      } else {
        alert.dismiss();
      }
      return alertText;
    } finally {
      acceptNextAlert = true;
    }
  }*/
	
	@BeforeMethod
	public void mayBeLogout() {
		if (app.getUserHelper().isLoggedIn()) {
			return;
		}
		app.getUserHelper().loginAs(ADMIN);
	}

	@Test
	public void searchBad() {
		List<Film> films = app.getFilmHelper().search("bla bla");
	    assertEquals(0, films.size());
	}
}
